package com.csdn.server;

import com.csdn.actuator.Actuator;
import com.csdn.actuator.HttpActuator;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.StatisticsHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.thread.ExecutorThreadPool;
import org.eclipse.jetty.util.thread.ThreadPool;

import javax.servlet.Servlet;


public class Test {
    public static void main(String[] args) throws Exception {
        ThreadPool threadPool = new ExecutorThreadPool();
        Server server = new Server(8089);
        ServletHandler handler = new ServletHandler();
        Actuator actuator = new HttpActuator();
        Servlet containerServlet = new ContainerServlet(actuator);
        ServletHolder servletHolder = new ServletHolder(containerServlet);
        handler.addServletWithMapping(servletHolder, "/*");
        //  server.setHandler(handler);
        ServletContextHandler contextHandler = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
        contextHandler.setServletHandler(handler);
        StatisticsHandler statisticsHandler = new StatisticsHandler();
        statisticsHandler.setHandler(server.getHandler());
        server.setHandler(statisticsHandler);
        server.setStopAtShutdown(false);
        server.start();
        server.join();
    }

}
